package com.dman.multi.core;

import org.apache.pivot.wtk.BoxPane;
import org.apache.pivot.wtk.media.Image;

public class DownloadView {
	
	private Image downloadState;
	private String fileName;
	private String size;
	private BoxPane percentComplete;
	private String downloadSpeed;
	private String sections;
	private String startDate;
	private String completeDate;

	public Image getDownloadState() {
		return downloadState;
	}

	public void setDownloadState(Image downloadState) {
		this.downloadState = downloadState;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public BoxPane getPercentComplete() {
		return percentComplete;
	}

	public void setPercentComplete(BoxPane percentComplete) {
		this.percentComplete = percentComplete;
	}

	public String getDownloadSpeed() {
		return downloadSpeed;
	}

	public void setDownloadSpeed(String downloadSpeed) {
		this.downloadSpeed = downloadSpeed;
	}

	public String getSections() {
		return sections;
	}

	public void setSections(String sections) {
		this.sections = sections;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getCompleteDate() {
		return completeDate;
	}

	public void setCompleteDate(String completeDate) {
		this.completeDate = completeDate;
	}
	
	

	/*public Image getDownloadState() {
		Image img = null;
		DownloadState state = download.getDownloadState();
		String location = null;
		switch(state){
		case COMPLETE:
			location = "done-mini.png";
			break;
		case NEW:
		case SCHEDULED:
			location = "schedule-mini.png";
			break;
		case PAUSED:
			location = "stop-mini.png";
			break;
		case RUNNING:
			location = "down-mini.png";
			break;
		}
		try {
			URL url = Image.class.getResource(location);
			img = Image.load(url);
		} catch (TaskExecutionException e) {
			e.printStackTrace();
		}
		return img;
	}

	
	public String getFileName() {
		return download.getFileName();
	}

	
	public String getSize() {
		double size = download.getSize();
		int units = 0;
		while(size > 1024){
			size = size / 1024;
			++units;
		}
		
		return size + " " + exponentToAbb.get(units);
	}

	
	public String getPercentComplete() {
		double pc = download.getPercentComplete();
		long percent = Math.round(pc * 10);
		long pq = percent / 10;
		long pr = percent % 10;
		return pq + "." + pr + "%";
	}

	
	public String getDownloadSpeed() {
		double speed = download.getDownloadSpeed();
		int units = 0;
		while(speed > 1024){
			speed = speed / 1024;
			++units;
		}
		
		return speed + " " + exponentToAbb.get(units) + "/s";
	}

	
	public String getSections() {
		return download.getSections();
	}

	
	public String getStartDate() {
		Calendar cal = download.getStartDate();
		Date date = new Date(cal.getTimeInMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm");
		String sDate = sdf.format(date);
		return sDate;
	}

	
	public String getCompleteDate() {
		Calendar cal = download.getCompleteDate();
		String sDate = "";
		if(cal != null){
			Date date = new Date(cal.getTimeInMillis());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm");
			sDate = sdf.format(date);
		}
		return sDate;
	}*/

}
